package com.spica.spicaschool.network

import com.skydoves.sandwich.ApiResponse
import com.spica.spicaschool.bean.UpdateUserInfoResponse
import com.spica.spicaschool.bean.User
import com.spica.spicaschool.bean.UserBody
import com.spica.spicaschool.bean.diary.Diary
import com.spica.spicaschool.bean.group.Group
import com.spica.spicaschool.bean.news.NewsResponse
import com.spica.spicaschool.bean.newsdetail.NewsDetailResponse
import com.spica.spicaschool.network.service.SpicaSchoolService
import javax.inject.Inject

class SpicaClient @Inject constructor(
    private val spicaSchoolService: SpicaSchoolService
) {


    /**
     * 网络请求获取用户信息
     */
    suspend fun fetchUserInfo(token: String): ApiResponse<ResponseList<User>> =
        spicaSchoolService.fetchUserInfo(token)


    /**
     * 获取用户身体信息
     */
    suspend fun fetchUserBodyInfo(token: String): ApiResponse<ResponseList<UserBody>> =
        spicaSchoolService.fetchUserBodyInfo(token)


    /**
     * 网络请求获取圈子页信息流
     */
    suspend fun fetchCircleDiary(
        type: Int,
        token: String,
        pageNum: Int,
        pageSize: Int
    ): ApiResponse<ResponseList<Diary>> =
        spicaSchoolService.fetchCircleDiaries(type, token, pageNum, pageSize)


    /**
     * 获取新闻列表
     */
    suspend fun fetchNews(page: Int): ApiResponse<NewsResponse> =
        spicaSchoolService.fetchNews(page = page)

    /**
     * 获取新闻详情
     */
    suspend fun fetchNewsDetail(id: String): ApiResponse<NewsDetailResponse> =
        spicaSchoolService.fetchNewsDetail(id)


    /**
     * 获取问答列表
     */
    suspend fun fetchConsults(
        token: String,
        pageNum: Int,
        pageSize: Int
    ): ApiResponse<ResponseList<Diary>> =
        spicaSchoolService.fetchDiaries(
            type = 3,
            token = token,
            pageNum = pageNum,
            pageSize = pageSize
        )


    /**
     * 获取小组列表
     */
    suspend fun fetchGroups(
        token: String,
        pageNum: Int,
        pageSize: Int
    ): ApiResponse<ResponseList<Group>> = spicaSchoolService.fetchgroups(
        token, pageNum, pageSize
    )

    /**
     * 更新用户信息
     */
    suspend fun updateUserInfo(
        token: String,
        head: String? = null,
        nickname: String? = null,
        selfdes: String? = null,
        gender: Int? = null,
        birthday: String? = null,
        height: Int? = null,
        weight: Int? = null,
        vialCap: Int? = null
    ): ApiResponse<UpdateUserInfoResponse> = spicaSchoolService.updateUser(
        token,
        head,
        nickname,
        selfdes,
        gender,
        birthday,
        height,
        weight,
        vialCap
    )


}